﻿using System;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MvvmFx.Common.Helpers
{
    /// <summary>
    /// Utility class for image functions
    /// </summary>
    public static class ImageHelper
    {
        /// <summary>
        /// Opens an Image file as an ImageSource
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static ImageSource GetImageSource(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(string.Format("Image file ({0}) is not found", fileName));
            }

            Uri uri = new Uri(fileName, UriKind.Absolute);
            BitmapImage bmpImage = new BitmapImage(uri);
            return bmpImage;
        }
    }
}